﻿@{
    ViewBag.Title = "Upload";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Upload</h2>

@Styles.Render("~/Scripts/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css")
@Scripts.Render("~/Scripts/plupload/plupload.full.js")
@Scripts.Render("~/Scripts/plupload/jquery.plupload.queue/jquery.plupload.queue.js")

<script type="text/javascript">
    $(function () {
        $("#uploader").pluploadQueue({
            runtimes: 'flash,silverlight,html5,html4',
            url: '/photo/uploadfiles',
            max_file_size: '10mb',
            chunk_size: '2mb',
            unique_names: true,
            flash_swf_url: '/Scripts/plupload/plupload.flash.swf',
            silverlight_xap_url: '/Scripts/plupload/plupload.silverlight.xap',
            multiple_queues:true
        });

        $('form').submit(function (e) {
            var uploader = $('#uploader').pluploadQueue();

            if (uploader.files.length > 0) {
                uploader.bind('StateChanged', function () {
                    if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                        $('form')[0].submit();
                    }
                });
                uploader.start();
            } else {
                alert('You must queue at least one file.');
            }
            return false;
        });
    });
</script>

<div id="uploader">
	<p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>